package com.wym.exampleproject.distributedredislock.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class LockServiceImpl extends BaseService implements ILockService  {

    public static String key = "asd";
    public static int timeout = 10000000;


    @Override
    public void one() {
        try {
            if (lock2(key,timeout)) {
                log.info("one接口 获取锁");
                Thread.sleep(10000000);
            }else{
                log.info("one接口 获取锁失败");
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            unLock(key);
        }
    }

    @Override
    public void two() {
        try {
            if (lock2(key,timeout)) {
                log.info("two接口 获取锁");

            }else{
                log.info("two接口 获取锁失败");
            }
        }finally {
            unLock(key);
        }
    }
}
